Skip to content

estimate_means warning/error cut off? "Could not calculate standard errors for contrasts. This can happen when random effects are involved"#595

Merged
strengejacke merged 2 commits into
mainfrom
strengejacke/issue578
Feb 14, 2026
Merged

estimate_means warning/error cut off? "Could not calculate standard errors for contrasts. This can happen when random effects are involved"#595
strengejacke merged 2 commits into
mainfrom
strengejacke/issue578

Conversation

@strengejacke
Copy link
Copy Markdown
Member

Fixes #578

…rrors for contrasts. This can happen when random effects are involved"

Fixes #578
@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello @strengejacke, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses an issue where error messages related to standard error calculation were truncated, particularly when random effects were involved. The changes ensure that the full diagnostic message, including potential suggestions for resolution, is displayed to the user. Additionally, internal code formatting has been improved for better maintainability.

Highlights

  • Error Message Clarity: The primary issue of truncated error messages when standard errors cannot be calculated has been resolved, ensuring users receive complete diagnostic information.
  • Code Readability Improvements: Several internal utility functions and conditional statements have been refactored for better code formatting and readability.
  • Package Version Update: The modelbased package version has been incremented to 0.13.1.3.
Changelog
  • DESCRIPTION
    • Updated package version to 0.13.1.3.
  • NEWS.md
    • Documented fix for truncated error messages when standard errors are not calculated.
  • R/estimate_means.R
    • Modified the call to the internal .check_standard_errors function to pass the 'by' attribute.
  • R/utils.R
    • Refactored internal helper functions for improved code readability.
    • Adjusted the error message logic in .check_standard_errors to ensure full message display and conditional suggestion.
Activity
  • No specific activity (comments, reviews, or progress updates) has been recorded for this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request fixes an issue where a warning/error message about failing to calculate standard errors was being truncated. The fix involves shortening the initial message and conditionally adding more details. The changes are logical and correctly address the problem.

I've added one comment with a suggestion to improve the message formatting by using paste0() instead of c() to construct the message string. This will prevent unintended spaces and ensure newlines are handled correctly. The other changes are stylistic improvements for readability, which are well done.

Comment thread R/utils.R
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes the incomplete/truncated .check_standard_errors() message seen in estimate_means() by ensuring the warning only suggests follow-up code when the necessary context (by) is available, and by passing resolved by terms into the check.

Changes:

  • Reworked .check_standard_errors() message assembly to avoid printing “You may try following:” without a snippet.
  • Updated estimate_means() to pass the resolved by attribute into .check_standard_errors().
  • Bumped package version and added a NEWS entry describing the fix.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
R/utils.R Adjusts warning message construction in .check_standard_errors() so the follow-up suggestion is only appended when applicable.
R/estimate_means.R Passes attributes(means)$by into .check_standard_errors() so the suggested code snippet can be generated.
NEWS.md Documents the truncated-message fix.
DESCRIPTION Version bump for the patch release.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread R/utils.R Outdated
if (!is.null(by_vars)) {
msg <- c(msg, insight::color_text(code_snippet, "green"), "\n")
msg <- c(
paste0(msg, "You may try following:"),
Copy link

Copilot AI Feb 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The constructed message is missing whitespace between sentences: format_message(..."involved.") is concatenated with "You may try following:" via paste0() without a leading space/newline, so users will see ...involved.You may try following:. Add a separator (e.g., " You may..." or use paste() with sep = " ") so the warning reads correctly.

Suggested change
paste0(msg, "You may try following:"),
paste0(msg, " You may try following:"),

Copilot uses AI. Check for mistakes.
Comment thread R/estimate_means.R
Comment on lines 467 to +473
# sanity check - did method return standard errors?
.check_standard_errors(out = means, model = model, verbose = verbose)
.check_standard_errors(
out = means,
by = attributes(means)$by,
model = model,
verbose = verbose
)
Copy link

Copilot AI Feb 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR changes the standard-error warning behavior for estimate_means() by passing the resolved by variables into .check_standard_errors(), but there is no test asserting the warning now includes the suggested follow-up code (and no longer ends with a dangling "You may try following:"). Consider adding an expect_message() (or snapshot) for a model that yields SE = NA to prevent regressions in this user-facing output.

Copilot uses AI. Check for mistakes.
@strengejacke strengejacke merged commit d28c788 into main Feb 14, 2026
14 of 22 checks passed
@strengejacke strengejacke deleted the strengejacke/issue578 branch February 14, 2026 12:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

estimate_means warning/error cut off? "Could not calculate standard errors for contrasts. This can happen when random effects are involved"

2 participants